#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_grad3.info <<'%EOF%'
   cc_grad3
   --------
   Molecule:         N2 in C1
   Wave Function:    CCSD
   Test Purpose:     Analytical gradient
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_grad3.mol <<'%EOF%'
INTGRL
first order property calculation on N2                                          
small test-basis                                                                
    1  0 0  X  Y  Z   0.10D-14
        7.    2    3    2    1    1
N        0.0000000000000     0.0000000000000     1.0371575000000
N        0.0000000000000     0.0000000000000    -1.0371575000000
H   8    2
     9046.0000000000        0.0007000000       -0.0001530000
     1357.0000000000        0.0053890000       -0.0012080000
      309.3000000000        0.0274060000       -0.0059920000
       87.7300000000        0.1032070000       -0.0245440000
       28.5600000000        0.2787230000       -0.0674590000
       10.2100000000        0.4485400000       -0.1580780000
        3.8380000000        0.2782380000       -0.1218310000
        0.7466000000        0.0154400000        0.5490030000
H   2    2
        0.2248000000        1.0000000000        0.0000000000
        0.0612400000        0.0000000000        1.0000000000
H   5    3
       13.5500000000        0.0399190000        0.0000000000        0.0000000000
        2.9170000000        0.2171690000        0.0000000000        0.0000000000
        0.7973000000        0.5103190000        0.0000000000        0.0000000000
        0.2185000000        0.0000000000        1.0000000000        0.0000000000
        0.0561100000        0.0000000000        0.0000000000        1.0000000000
H   2    2
        0.8170000000        1.0000000000        0.0000000000
        0.2300000000        0.0000000000        1.0000000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_grad3.dal <<'%EOF%'
**DALTON INPUT
.DIRECT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
.DEROVL
.DERHAM
**WAVE FUNCTION
.CC
*SCF INP
.THRESH
 1.0D-10
.DOUBLY OCCUPIED
 7
*CC INP
.CCSD
.PRINT
  2
.THRENR
1.0D-08
.THRLEQ
1.0D-07
.NSYM
1
.FROIMP
2
0
*DERIVATIVES
**END OF DALTON INPUT
%EOF%
#######################################################################

 
#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_grad3.check
cat >>cc_grad3.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 (frozen core) and CCSD (frozen core) energies: 
CRIT1=`$GREP "Final * HF energy: * -108\.96064996" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * -109\.27784304" $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy: * -109\.28046028" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=5
ERROR[1]="SCF, MP2 OR CCSD ENERGY NOT CORRECT"

# CCSD (frozen core) total molecular gradient: 
CRIT1=`$GREP "N * (\-| )0?\.0000000000 * (\-| )0?\.0000000000 * -0?\.05049652" $log | wc -l`
TEST[2]=`expr $CRIT1` 
CTRL[2]=1
ERROR[2]="THE TOTAL MOLECULAR GRADIENT IS NOT CORRECT"

# CCSD (frozen core) nuclear repulsion gradient: 
CRIT1=`$GREP "N * -?0?\.0000000000 * -?0?\.0000000000 * -11\.38797917" $log | wc -l`
TEST[3]=`expr $CRIT1` 
CTRL[3]=1
ERROR[3]="THE NUCLEAR REPULSION GRADIENT IS NOT ORRECT"

# CCSD (frozen core) one-electron integral gradient: 
CRIT1=`$GREP "N * -?0?\.0000000000 * -?0?\.0000000000 * 24.6569955" $log | wc -l`
TEST[4]=`expr $CRIT1` 
CTRL[4]=1
ERROR[4]="THE ONE-ELECTRON INTEGRAL GRADIENT IS NOT CORRECT"

# CCSD (frozen core) nuclear two-electron integral gradient: 
CRIT1=`$GREP "N * (0| |\-0|\-)\.0000000000 * (0| |\-0|\-)\.0000000000 * -12.5650114" $log | wc -l`
TEST[5]=`expr $CRIT1` 
CTRL[5]=1
ERROR[5]="THE TWO-ELECTRON INTEGRAL GRADIENT IS NOT CORRECT"

# CCSD (frozen core) nuclear reorthonormalization gradient: 
CRIT1=`$GREP "N * (\-| )0?\.0000000000 * (\-| )0?\.0000000000 * -0?\.75450143" $log | wc -l`
TEST[6]=`expr $CRIT1` 
CTRL[6]=1
ERROR[6]="THE REORTHONORMALIZATION GRADIENT IS NOT ORRECT"


PASSED=1
for i in 1 2 3 4 5 6
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
chmod +x cc_grad3.check
#######################################################################
